package com.gxc.integer;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.Stack;

/**
 * 给定一个表达式，求其分数计算结果。
 *
 * 表达式的限制如下：
 *
 * 所有的输入数字皆为正整数（包括0）
 * 仅支持四则运算（+-*\/）和括号
*结果为整数或分数，分数必须化为最简格式（比如6，3/4，7/8，90/7）
*除数可能为0，如果遇到这种情况，直接输出"ERROR"
*输入和最终计算结果中的数字都不会超出整型范围
*用例输入一定合法，不会出现括号匹配的情况
*
*输入描述
*字符串格式的表达式，仅支持+-*\/，数字可能超过两位，可能带有空格，没有负数
*
*长度小于200个字符
*
*输出描述
*表达式结果，以最简格式表达
*
*如果结果为整数，那么直接输出整数
*如果结果为负数，那么分子分母不可再约分，可以为假分数，不可表达为带分数
*结果可能是负数，符号放在前面
 *
 * 解法：
 * 栈：先计算  *\/
 */
public class Expression {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String str = scanner.nextLine();

        Stack<String> stack = new Stack<>();
        boolean invalidFlag = false;
        int index = 0;
        StringBuilder numStr = new StringBuilder();
        while (index < str.length()) {
            if (invalidFlag) break;

            char c = str.charAt(index);
            //如果栈顶是 * / 则先计算
            if (!stack.isEmpty() && (stack.peek().equals("*") || stack.peek().equals("/"))) {
                while (index < str.length() && Character.isDigit(str.charAt(index))) {
                    numStr.append(str.charAt(index));
                    index++;
                }
                int b = Integer.parseInt(numStr.toString());
                numStr.setLength(0);
                if (stack.peek().equals("/") && b == 0) {
                    invalidFlag = true;
                    break;
                }
                String symbol = stack.pop();
                //翻转
                int a = Integer.parseInt(numStr.reverse().toString());
                if (symbol.equals("*")) {

                } else {

                }

            } else if (c == ' ') {

            }

            index++;
        }

        if (invalidFlag) {
            System.out.println("ERROR");
        }
    }

    static class Fractions {
        int fa; // 分母
        int ch; // 分子

        Fractions() {}
        Fractions(int fa, int ch) {
            this.fa = fa;
            this.ch = ch;
        }
    }

    // 操作数栈
    static Stack<Fractions> operaorNum = new Stack<>();
    // 操作符栈
    static Stack<Character> operatorSign = new Stack<>();
    // 记录除0的非常操作
    static boolean invalidFlag = false;

    // 四则运算
    static void calc() {
        Fractions b = operaorNum.pop();
        Fractions a = operaorNum.pop();
        char op = operatorSign.pop();
        Fractions result = new Fractions();

        switch (op) {
            case '+':
                result.fa = a.fa * b.fa;
                result.ch = a.ch * b.fa + b.ch * a.fa;
                break;
            case '-':
                result.fa = a.fa * b.fa;
                result.ch = a.ch * b.fa - b.ch * a.fa;
                break;
            case '*':
                result.fa = a.fa * b.fa;
                result.ch = a.ch * b.ch;
                break;
            case '/':
                result.fa = a.fa * b.ch;
                result.ch = a.ch * b.fa;
                break;
        }
        if (result.fa == 0) {
            invalidFlag = true;
        }
        operaorNum.push(result);
    }

    // 求最大公约数
    static int gcd(int a, int b) {
        while (b != 0) {
            int temp = b;
            b = a % b;
            a = temp;
        }
        return a < 0 ? -a : a; // 确保结果非负
    }

    // 解析表达式
    static String solve(String express) {
        Map<Character, Integer> opertorPriorty = new HashMap<>();
        opertorPriorty.put('+', 1);
        opertorPriorty.put('-', 1);
        opertorPriorty.put('*', 2);
        opertorPriorty.put('/', 2);

        StringBuilder numStr = new StringBuilder();
        int pos = 0;

        while (pos < express.length()) {
            if (invalidFlag) {
                break;
            }
            char c = express.charAt(pos);
            if (Character.isDigit(c)) {
                // 获取完整数字
                while (Character.isDigit(c)) {
                    numStr.append(c);
                    if (pos + 1 >= express.length()) {
                        break;
                    }
                    pos++;
                    c = express.charAt(pos);
                }
                // 压入操作数栈
                operaorNum.push(new Fractions(1, Integer.parseInt(numStr.toString())));
                numStr.setLength(0); // 清空
            }
            if (c == '+' || c == '-' || c == '*' || c == '/') {
                while (!operatorSign.isEmpty() && operatorSign.peek() != '(' && opertorPriorty.get(c) <= opertorPriorty.get(operatorSign.peek())) {
                    calc();
                }
                operatorSign.push(c);
            } else if (c == ')') {
                while (operatorSign.peek() != '(') {
                    calc();
                }
                // 移除对应的(
                operatorSign.pop();
            } else if (c == '(') {
                // 压栈
                operatorSign.push(c);
            }
            pos++;
        }

        while (operaorNum.size() > 1) {
            calc();
        }

        Fractions result = operaorNum.pop();
        if (result.fa == 0 || invalidFlag) {
            return "ERROR";
        }
        // 最简分数处理
        int k = gcd(result.fa, result.ch);
        result.fa /= k;
        result.ch /= k;

        String sign = result.fa * result.ch < 0 ? "-" : "";

        int fa = Math.abs(result.fa);
        int ch = Math.abs(result.ch);

        if (fa == 1) {
            return sign + ch;
        } else {
            return sign + ch + "/" + fa;
        }
    }

    public static void main2(String[] args) {
        Scanner sc = new Scanner(System.in);
        String express = sc.nextLine();
        String result = solve(express);
        System.out.println(result);
    }
}
